<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateProductsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->string('name', 30)->unique()->comment("商品名称");
            $table->string('unit', 10)->default('份')->comment('商品单位');
            $table->string('perprice')->default(0)->comment('商品单价');
            $table->string('description')->nullable()->comment("商品描述");
            $table->string('image')->nullable()->comment('商品图片');
            $table->string('abbr')->nullable()->comment('拼音缩写');
            $table->foreignId('category_id')->constrained('categories')->onDelete('cascade')->comment('所属分类');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('products');
    }
}
